package com.slipper.codeless.resolve.query;

import com.slipper.util.Tool;

import java.util.ArrayList;
import java.util.List;

public class Condition {
    /** like查询 */
    public static final String MATCH_MODE_LIKE = "模糊";
    /** 小于 */
    public static final String MATCH_MODE_LT = "小于";
    /** 小于等于 */
    public static final String MATCH_MODE_LTE = "小于等于";
    /** 等于 */
    public static final String MATCH_MODE_EQU = "等于";
    /** 大于 */
    public static final String MATCH_MODE_GT = "大于";
    /** 大于等于 */
    public static final String MATCH_MODE_GTE = "大于等于";
    /** 不等于 */
    public static final String MATCH_MODE_NO_EQU = "不等于";
    /** in查询 */
    public static final String MATCH_MODE_IN = "包含";
    /** 递归查询 */
    public static final String MATCH_MODE_RECURSIVE = "递归";
    /** between and查询 */
    public static final String MATCH_MODE_BTN = "btn";
    /** 范围查询，大于且小于 */
    public static final String MATCH_MODE_RG = "rg";
    /** 范围查询，大于等于且小于等于 */
    public static final String MATCH_MODE_RGE = "rge";
    /** 组织机构层级查询 */
    public static final String MATCH_MODE_ORG_LEVEL = "orgLevel";
    /** 过滤掉admin */
    public static final String MATCH_MODE_NOT_ADMIN = "no_admin";

    private boolean alias = false;
    private String connectSymbol;
    private String frontBracket;
    private String fieldName;
    private String fieldType;
    private String behindBracket;
    private String aliasName;
    private int ordinal = 0;
    private List<ConditionItem> itemList = new ArrayList<>();

    public Condition() {}

    public Condition(String fieldName, String fieldType, String matchMode, Object matchValue) {
        this.connectSymbol = " and ";
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        itemList.add(new ConditionItem(matchMode, matchValue));
    }

    public Condition(
            boolean alias,
            String connectSymbol,
            String fieldName,
            String fieldType,
            String matchMode,
            Object matchValue) {
        this.alias = alias;
        this.connectSymbol = connectSymbol;
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        itemList.add(new ConditionItem(matchMode, matchValue));
    }

    public Condition(
            String connectSymbol,
            String frontBracket,
            String fieldName,
            String fieldType,
            String matchMode,
            Object matchValue,
            String behindBracket,
            int ordinal) {
        this.connectSymbol = Tool.isBlank(connectSymbol) ? "and" : connectSymbol;
        this.frontBracket = frontBracket;
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        this.behindBracket = behindBracket;
        this.ordinal = ordinal;
        itemList.add(new ConditionItem(matchMode, matchValue));
    }

    public Condition(
            String fieldName,
            String fieldType,
            String tableName,
            String idName,
            String pidName,
            String matchMode,
            Object matchValue) {
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        itemList.add(new ConditionItem(tableName, idName, pidName, matchMode, matchValue));
    }

    public boolean isAlias() {
        return alias;
    }

    public void setAlias(boolean alias) {
        this.alias = alias;
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getFieldType() {
        return fieldType;
    }

    public void setFieldType(String fieldType) {
        this.fieldType = fieldType;
    }

    public String getConnectSymbol() {
        return connectSymbol;
    }

    public void setConnectSymbol(String connectSymbol) {
        this.connectSymbol = connectSymbol;
    }

    public String getFrontBracket() {
        return frontBracket;
    }

    public void setFrontBracket(String frontBracket) {
        this.frontBracket = frontBracket;
    }

    public String getBehindBracket() {
        return behindBracket;
    }

    public void setBehindBracket(String behindBracket) {
        this.behindBracket = behindBracket;
    }

    public String getAliasName() {
        return aliasName;
    }

    public void setAliasName(String aliasName) {
        this.aliasName = aliasName;
    }

    public int getOrdinal() {
        return ordinal;
    }

    public void setOrdinal(int ordinal) {
        this.ordinal = ordinal;
    }

    public List<ConditionItem> getItemList() {
        return itemList;
    }

    public void setItemList(List<ConditionItem> itemList) {
        this.itemList = itemList;
    }
}
